package utils.common;

import java.util.Collections;
import java.util.List;

/**
 * @author Zhou Yifan
 */
public class ArrayUtils {

    public static <T> List<T> asUnmodifiableList(T[] array) {
        return asUnmodifiableList(array, 0, array.length);
    }

    public static <T> List<T> asUnmodifiableList(T[] array, int fromIndex, int toIndex) {
        if (toIndex < fromIndex) {
            throw new IllegalArgumentException("The toIndex less than fromIndex!");
        }
        if (fromIndex < 0) {
            throw new IllegalArgumentException("The fromIndex is negative!");
        }
        if (toIndex > array.length) {
            throw new IllegalArgumentException("The toIndex great than the length of array!");
        }

        if (fromIndex == toIndex) {
            return Collections.emptyList();
        }
        return new ReadonlyArrayListWrapper<T>(array, fromIndex, toIndex);
    }

}
